package etm.servlet.junta;

import java.io.IOException;
import java.sql.Date;
import java.sql.Time;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import etm.excepcion.DAOExcepcion;
import etm.negocio.GestionJunta;
import etm.negocio.GestionResidente;

/**
 * Servlet implementation class JuntaModificaServlet
 */
@WebServlet("/JuntaModificaServlet")
public class JuntaModificaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public JuntaModificaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		GestionJunta negocio = new GestionJunta();
		
		
		System.out.println("Dentro de doPost del servlet JuntaModificaServlet");
		int intidjunta = Integer.valueOf(request.getParameter("txidjunta"));
		String fecha = request.getParameter("txfecha");
		System.out.println("fecha:"+fecha);
		Date datFecha = Date.valueOf(fecha);
		String hora = request.getParameter("txhora");
		if (hora.length()==5){hora=hora+":00";}
		System.out.println("hora:"+hora);
		Time tmHora = Time.valueOf(hora);
		
		String strTema=request.getParameter("txasunto");
		try {
			negocio.actualizar(intidjunta,datFecha,tmHora,strTema);
			response.sendRedirect(request.getContextPath()	+ "/JuntaBuscaServlet");
		} catch (DAOExcepcion e) {
			System.out.println(e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
	}

}
